package registeringSystem;

import static org.junit.Assert.*;

import java.util.ArrayList;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class UserTest 
{
	User user1, user2, user3;
	
	@Before
	public void setUp() throws Exception 
	{
		user1 = new User();
		
		user2 = new User("Name", 
				         "12345","12345 Street Avenue, City, MD, USA, 09876",
						 "email@host.com", 1, "password",
						 new ArrayList<CoursePlusCharacter>(), 
						 new ArrayList<Course>(),
						 new ArrayList<CoursePlusCharacter>(), 0.0, true,
						 "major", "minor", false, "dept", "none", 
						 new ArrayList<Course>(), new ArrayList<Course>(),
						 false);
		
		user3 = new User(user1);
	}

	@After
	public void tearDown() throws Exception 
	{
		user1 = user2 = user3 = null;
	}

	@Test
	public void testUser() 
	{
		assertTrue(user1 != null);
	}

	@Test
	public void testUser2() 
	{
		assertTrue(user2 != null);
	}

	@Test
	public void testUserUser() 
	{
		assertTrue(user1.compareTo(user3) == 0);
	}

	@Test
	public void testGetTheKey() 
	{
		assertTrue(user1.getTheKey() == null);
	}

	@Test
	public void testGetName() 
	{
		assertTrue(user2.getName().equals("Name"));
	}

	@Test
	public void testGetCampusID() 
	{
		assertTrue(user2.getCampusID().equals("12345"));
	}

	@Test
	public void testGetAddress() 
	{
		assertTrue(user2.getAddress().equals("12345 Street Avenue, City, MD, USA, 09876"));
	}

	@Test
	public void testGetEmailAddress() 
	{
		assertTrue(user2.getEmailAddress().equals("email@host.com"));
	}

	@Test
	public void testGetPermissionLevel() 
	{
		assertTrue(user2.getPermissionLevel() == 1);
	}

	@Test
	public void testGetPassword() 
	{
		assertTrue(user2.getPassword().equals("password"));
	}

	@Test
	public void testGetCurrentCoursesForStudent() 
	{
		assertTrue(user2.getCurrentCoursesForStudent().equals(new ArrayList<CoursePlusCharacter>()));
	}

	@Test
	public void testGetCompletedCourses() 
	{
		assertTrue(user2.getCompletedCourses().equals(new ArrayList<CoursePlusCharacter>()));
	}

	@Test
	public void testGetGPA() 
	{
		assertTrue(user2.getGPA() == 0.0);
	}

	@Test
	public void testShowNumberOfCreditsForThisSemester() 
	{
		assertTrue(user2.showNumberOfCreditsForThisSemester() == 0);
	}

	@Test
	public void testGetIsAlumni() 
	{
		assertTrue(user2.getIsAlumni());
	}

	@Test
	public void testGetMajor() 
	{
		assertTrue(user2.getMajor().equals("major"));
	}

	@Test
	public void testGetMinor() 
	{
		assertTrue(user2.getMinor().equals("minor"));
	}

	@Test
	public void testGetIsGradStudent() 
	{
		assertFalse(user2.getIsGradStudent());
	}

	@Test
	public void testGetDepartment() 
	{
		assertTrue(user2.getDepartment().equals("dept"));
	}

	@Test
	public void testGetLinkToTeacherRating() 
	{
		assertTrue(user2.getLinkToTeacherRating().equals("none"));
	}

	@Test
	public void testGetTeachingTheseCourses() 
	{
		assertTrue(user2.getTeachingTheseCourses().equals(new ArrayList<Course>()));
	}

	@Test
	public void testGetPreviousCoursesTaught() 
	{
		assertTrue(user2.getTeachingTheseCourses().equals(new ArrayList<Course>()));
	}

	@Test
	public void testGetWaitListedCourses() 
	{
		assertTrue(user2.getWaitListedCourses().equals(new ArrayList<Course>()));
	}

	@Test
	public void testGetHasPermissionToExceedMaxCredits() 
	{
		assertFalse(user2.getHasPermissionToExceedMaxCredits());
	}

	@Test
	public void testSetName() 
	{
		try 
		{
			user1.setName("name");
		} 
		
		catch (NullReferenceException e) 
		{
			;
		}
		assertTrue(user1.getName().equals("name"));
	}

	@Test
	public void testSetCampusID() 
	{
		try 
		{
			user1.setCampusID("12345");
		} 
		
		catch (NullReferenceException e) 
		{
			;
		}
		assertTrue(user1.getCampusID().equals("12345"));
	}

	@Test
	public void testSetAddress() 
	{
		try 
		{
			user1.setAddress("12345 address");
		} 
		
		catch (NullReferenceException e) 
		{
			;
		}
		assertTrue(user1.getAddress().equals("12345 address"));
	}

	@Test
	public void testSetEmailAddress() 
	{
		try 
		{
			user1.setEmailAddress("something@email.com");
		} 
		
		catch (NullReferenceException e) 
		{
			;
		}
		assertTrue(user1.getEmailAddress().equals("something@email.com"));
	}

	@Test
	public void testSetPermissionLevel() 
	{
		try 
		{
			user1.setPermissionLevel(9);
		} 
		
		catch (NotValidArgumentException e) 
		{	
			;
		}
		assertTrue(user1.getPermissionLevel() == 9);
	}

	@Test
	public void testSetPassword() 
	{
		try 
		{
			user1.setPassword("password");
		} 
		
		catch (NullReferenceException e) 
		{
			;
		}
		assertTrue(user1.getPassword().equals("password"));
	}

	@Test
	public void testSetCurrentCoursesForStudent1() 
	{
		try
		{
			user1.setCurrentCoursesForStudent(new ArrayList<CoursePlusCharacter>());			
		} 
		
		catch (Exception e)
		{
			;
		}
		assertTrue(user1.getCurrentCoursesForStudent().size()==0);
	}
	
	@Test
	public void testSetCompletedCourses() 
	{
		try
		{
			user1.setCompletedCourses(new ArrayList<CoursePlusCharacter>());			
		} 
		
		catch (Exception e)
		{
			;
		}
		assertTrue(user1.getCompletedCourses().size()==0);
	}

	@Test
	public void testSetGPA() 
	{
		try
		{
			user1.setGPA(3.2);
		} 
		
		catch(Exception e)
		{
			;
		}
		assertTrue(user1.getGPA()==3.2);
	}

	@Test
	public void testSetIsAlumni() 
	{
		try
		{
			user1.setIsAlumni(true);
		} 
		
		catch(Exception e)
		{
			;
		}
		assertTrue(user1.getIsAlumni());
	}

	@Test
	public void testSetMajor() 
	{
		try
		{
			user1.setMajor("English");
		} 
		
		catch(Exception e)
		{
			;
		}
		assertTrue(user1.getMajor().equals("English"));
	}

	@Test
	public void testSetMinor() 
	{
		try
		{
			user1.setMinor("Math");
		} 
		
		catch(Exception e)
		{
			;
		}
		assertTrue(user1.getMinor().equals("Math"));
	}

	@Test
	public void testSetIsGradStudent() 
	{
		try
		{
			user1.setIsGradStudent(true);
		}
		
		catch(Exception e)
		{
			;
		}
		assertTrue(user1.getIsGradStudent());
	}

	@Test
	public void testSetDepartment() 
	{
		try
		{
			user1.setDepartment("Economics");
		}
		
		catch(Exception e){
			;
		}
		assertTrue(user1.getDepartment().equals("Economics"));
	}

	@Test
	public void testSetLinkToTeacherRating()
	{
		try
		{
			user1.setLinkToTeacherRating("test");
		}
		
		catch(Exception e)
		{
			;
		}
		assertTrue(user1.getLinkToTeacherRating().equals("test"));
	}

	@Test
	public void testSetPreviousCoursesTaught() 
	{
		try
		{
			user1.setPreviousCoursesTaught(new ArrayList<Course>());
		} 
		
		catch(Exception e)
		{
			;
		}
		assertTrue(user1.getPreviousCoursesTaught().size()==0);
	}

	@Test
	public void testSetHasPermissionToExceedMaxCredits()
	{
		try
		{
			user1.setHasPermissionToExceedMaxCredits(true);
		} 
		
		catch(Exception e)
		{
			;
		}
		assertTrue(user1.getHasPermissionToExceedMaxCredits());
	}

	@Test
	public void testSetWaitListedCourses() 
	{
		try
		{
			user1.setWaitListedCourses(new ArrayList<Course>());
		} 
		
		catch(Exception e)
		{
			;
		}
		assertTrue(user1.getWaitListedCourses().size()==0);
	}

	@Test
	public void testCompareTo() 
	{
		assertTrue(user1.compareTo(user2)<0);
	}

	@Test
	public void testEqualsUser() 
	{
		assertTrue(user1.equals(user1));
	}
} // end of UserTest class